package com.adinnet.admin.word.controller;


import com.adinnet.admin.word.model.Word;
import com.adinnet.admin.word.service.WordService;
import com.adinnet.core.JsonResult;
import com.adinnet.core.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 * 重点词汇表 前端控制器
 * </p>
 *
 * @author zYshuai
 * @since 2020-12-11
 */
@Controller
@RequestMapping("/word")
public class WordController {

    @Autowired
    private WordService wordService;

    /**
     * 重点词汇列表
     **/
    @ResponseBody
    @RequestMapping("/list")
    public PageResult<Word> list(String keyword) {
        List<Word> wordList = wordService.wordList(keyword);
        return new PageResult<>(wordList);
    }

    /**
     * 添加重点词汇
     */
    @RequestMapping("/add")
    @ResponseBody
    public JsonResult add(Word word) {
        if (wordService.save(word)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }

    /**
     * 修改重点词汇
     */
    @RequestMapping("/update")
    @ResponseBody
    public JsonResult update(Word word) {
        if (wordService.updateById(word)) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    /**
     * 删除重点词汇
     */
    @RequestMapping("/delete")
    @ResponseBody
    public JsonResult delete(Integer wordId) {
        return wordService.delete(wordId);
    }

}
